#include "widget.h"
#include "instructionwidget.h"
#include "qboxlayout.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    //主界面背景
    maininterface.setParent(this);
    QPixmap p1=QPixmap("3.png");
    maininterface.setPixmap(p1);
    this->setFixedSize(500,280);

    //主界面按钮
    start .setText("开始");
    start.setParent(this);
    instruct.setText("介绍");
    instruct.setParent(this);
    title.setText("Tom And Jerry");
    title.setParent(this);
    ctom .setText("Tom");
    ctom.setParent(this);
    cjerry.setText("Jerry");
    cjerry.setParent(this);

    //主界面贴图
    t.setPixmap(QPixmap("Tom"));
    t.setParent(this);
    j.setPixmap(QPixmap("Jerry"));
    j.setParent(this);
    t.move(40,110);
    j.move(180,110);

    // 设置按钮大小和位置
    title.setFixedSize(250,50);
    start.setFixedSize(80, 30);
    instruct.setFixedSize(80, 30);
    ctom.setFixedSize(80, 30);
    cjerry.setFixedSize(80, 30);

    int x = this->width(), y = this->height();
    title.move(10,10);
    start.move((x-100), y * 0.25);
    instruct.move((x-100), y * 0.5);
    ctom.move(40,230);
    cjerry.move(180,230);

    //连接信号与槽
    connect(&ctom,&QAbstractButton::clicked,this,&Widget::message1);
    connect(&cjerry,&QAbstractButton::clicked,this,&Widget::message2);
    connect(&ctom,&QAbstractButton::clicked,&game,&gamePlay::chtom);
    connect(&cjerry,&QAbstractButton::clicked,&game,&gamePlay::chjerry);

    connect(&instruct,&QAbstractButton::clicked,this,&Widget::gotoroleinstruction);
    connect(&start,&QAbstractButton::clicked,this,&Widget::gotogameplay);

    //标签、按钮样式
    title.setStyleSheet   ("background-color: transparent; border: none;font-family: 华文彩云; font-size: 40px; color: #F33333;");
    start.setStyleSheet   ("background-color: transparent; border: none;font-family: 华文琥珀; font-size: 24px; color: #F28034;");
    instruct.setStyleSheet("background-color: transparent; border: none;font-family: 华文琥珀; font-size: 24px; color: #F20004;");
    ctom.setStyleSheet    ("background-color: blue       ; border: none;font-family: 华文琥珀; font-size: 24px; color: #89FF7C;");
    cjerry.setStyleSheet  ("background-color: brown      ; border: none;font-family: 华文琥珀; font-size: 24px; color: #FF8737;");

    // 设置布局
    QVBoxLayout mainbox;
    mainbox.addWidget(&maininterface);
    this->setLayout(&mainbox);

}
void Widget::gotoroleinstruction()
{
    // 创建并显示 InstructionWidget 对象
    instructionwidget instructionWidget;
    instructionWidget.show();
}

void Widget:: gotogameplay(){

    game.setFixedSize(500,280);
    game.speed=1;
    game.temp.setPos(100,100);
    game.score=0;
    game.temp.life=1000;
    game.show();
};

Widget::~Widget() {}
